package com.mango.ch06;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import com.mango.Tools.DateUtils;

public class MovingAverageMapper extends Mapper<LongWritable, Text, ComposeKey, NaturalValue> {

	@Override
	protected void map(LongWritable key, Text value,
			Mapper<LongWritable, Text, ComposeKey, NaturalValue>.Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		String[] tokens = value.toString().split(",");
		long timeStamp = DateUtils.dateToLong(tokens[1]);
		Double val = Double.valueOf(tokens[2]);
		String name = tokens[0];
		context.write(new ComposeKey(name, timeStamp), new NaturalValue(val, timeStamp));
	}

}
